﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NHibernate;
using NHibernate.Linq;
using Lincolnwood.Foundation.Common.Data.NHibernate;
using Lincolnwood.Foundation.Common.Data;

namespace Lincolnwood.Foundation.Scheduling.Data.NHibernate
{
    public class NHibernateEventsRepository : NHibernateRepositoryBase<RecurrableEventDefinition, Guid>, IEventsRepository
    {

        public NHibernateEventsRepository(IUnitOfWork unitOfWork) : base((NHibernateUnitOfWork)unitOfWork)
        { }

        public IEnumerable<RecurrableEventDefinition> GetEventDefinitionsInRange(DateTime beginRange, DateTime endRange)
        {
            var results = from o in UnitOfWork.Session.Query<RecurrableEventDefinition>() 
                          where (o.StartTime >= beginRange && o.StartTime <= endRange) 
                                && (o.EndTime <= endRange && o.EndTime >= beginRange ) select o;

            return results.ToList<RecurrableEventDefinition>();
        }

        public override void Merge(RecurrableEventDefinition eventDefinition)
        {
            throw new NotImplementedException();
        }
        
    }
}
